<?php

namespace App\Http\Controllers\Mall;

use App\Models\Shop;
use App\Traits\Mall\ShopTrait;
use Illuminate\Http\Request;

class ShopController extends BaseController
{
    use ShopTrait;

    /**
     * @param Request $request
     * @param \Illuminate\Contracts\Pagination\Paginator $shops
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    protected function showShopsView(Request $request, $shops)
    {
        return $this->view('mall.shop.index', [
            'shops' => $shops,
            'pagination' => $shops->appends($request->except('page'))->render()
        ]);
    }

    /**
     * @param Request $request
     * @param Shop $shop
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    protected function showDetailView(Request $request, $shop)
    {
        $hotSales = $shop->items()->orderByDesc('sold')->take(15)->get();
        $items = $shop->items()->orderByDesc('itemid')->paginate(20);
        return $this->view('mall.shop.viewshop', [
            'shop' => $shop,
            'items' => $items,
            'pagination' => $items->appends($request->except('page'))->render(),
            'hotSales' => $hotSales
        ]);
    }
}
